package com.example.log.service.impl;

import com.example.log.mapper.LogMapper;
import com.example.log.pojo.UserLog;
import com.example.log.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;

    /**
     * @Async 注解描述的方法是一个异步切入点方法,
     * 这个方法调用会用在一个独立线程中.
     * @param log
     */
    @Async
    @Override
    public void saveLog(UserLog log) {
        System.out.println("LogServiceImpl.thread.name="+Thread.currentThread().getName());
        //假设记录日志的操作是比较耗时
        try{Thread.sleep(10000);}catch (Exception e){}
        logMapper.insert(log);
    }
}
